package ioperation;

import book.BOOK;
import book.BOOKLIST;

import java.util.Scanner;

public class ADDOPERATION implements IOPERATION{
    public void work(BOOKLIST booklist) {
        System.out.println("新增图书.....");
        int current = booklist.getUsedSize();
        if(current == booklist.getBooks().length){
            System.out.println("书架满了");
            return;
        }
        Scanner scanner = new Scanner(System.in);
        System.out.println("新增图书");
        System.out.println("请输入你的书名：");
        String name = scanner.nextLine();
        System.out.println("请输入作者：");
        String author = scanner.nextLine();
        System.out.println("请输入书的类型：");
        String type = scanner.nextLine();
        System.out.println("请输入价格：");
        int price = scanner.nextInt();
        BOOK newbook = new BOOK(name,author,type,price);
        for(int i = 0; i < current; i ++){
            BOOK book = booklist.getBooks(i);
            if(book.getName().equals(name)){
                System.out.println("有这本书不能插入");
                return;
            }
        }
        booklist.setBooks(current,newbook);
        booklist.setUsedSize(current + 1);
        System.out.println("新增成功");
    }
}
